package com.example.hospitallogin.assembly;

import com.example.hospitallogin.modules.login.dao.entity.EmailEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * @author qiancheng@cqxyy.net
 * @date 2022/10/15
 */
@Configuration
public class EmailConfig {
    @Autowired
    JavaMailSenderImpl mailSender;

    public void sendEmails(EmailEntity emailEntity){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(emailEntity.getEmailAddress());
        message.setFrom("2225802178@qq.com");
        if(emailEntity.getStatus() == 1){
            message.setSubject("岐黄中医在线管理系统-申请通过");
            message.setText("尊敬的" + emailEntity.getName() + "用户,您申请的" + emailEntity.getHospitalName() + "已验证通过，祝您使用愉快");
        }else{
            message.setSubject("岐黄中医在线管理系统-申请拒绝");
            message.setText("尊敬的" + emailEntity.getName() + "用户,您申请的" + emailEntity.getHospitalName() + "拒绝通过，原因如下:\n" + emailEntity.getContext());
        }
        mailSender.send(message);
    }
}
